/*
 * @Description: Delay queue
 * @Version: 1.0
 * @Autor: kane
 * @Date: 2021-02-15 22:26:59
 */ 

#ifndef _DELAY_QUEUE_H_
#define _DELAY_QUEUE_H_

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>

/**
 * @brief  Queue data structure.
 * @note   You can modify it for your application scene.
 * @param  m_cmd :event type.
 * @param  m_value :event value.
 * @param  m_offsetTime :Remaining time to send.
 * @param  next :The next chain structure,You don't have to pay attention.
 */
typedef struct delayQueueNode_T
{
	int32_t m_cmd;
	int32_t m_value;
	uint64_t m_offsetTime;
	struct delayQueueNode_T *next;
};

extern uint64_t g_delayQueueRunTime


/**
 * @brief  Time base increment handle.
 * @note   You should put it in the systick handle().
 * @retval None.
 */
void runTimeHandle(void);

/**
 * @brief  Gets the current elapsed time.
 * @note   In general, don't make changes.
 * @retval timing base (uint64_t).
 */
uint64_t getRunTime(void);

/**
 * @brief  Queue enqueuing function.
 * @note   
 * @param  **head_t: Handle to the queue.
 * @param  cmd: event type.
 * @param  value: event value.
 * @param  delayTime: Remaining time to send.
 * @retval None
 */
void insertNode(struct delayQueueNode_T **head_t, int32_t cmd, int32_t value, uint64_t delayTime);

/**
 * @brief  debug
 * @param  *head_t: Handle to the queue.
 * @retval None
 */
void print32_tNode(struct delayQueueNode_T *head_t);

/**
 * @brief  Take an item out of the queue.
 * @note   It can only be taken out if the remaining time is 0.
 * @param  **head_t: Handle to the queue.
 * @retval None
 */
void deleteNode(struct delayQueueNode_T **head_t);

#endif